#include "p2d_force_plane.h"

#include "script/scripthelper.h"
#include "util/log.h"		    // log
#include "util/common_macros.h"		// macros
#include "util/mmgr.h"		    // Needs to come in early

#include "math/mat4x4.h"

#include "dd/dd_man.h"

#include <cassert>
using namespace part2d;


P2DForceKillPlane::P2DForceKillPlane()
{
    m_Dist = 0.0f;
}

P2DForceKillPlane::~P2DForceKillPlane()
{

}
P2DForce*	P2DForceKillPlane::Clone()
{
	P2DForceKillPlane*	pForce = new P2DForceKillPlane();
	pForce->m_Dist	= m_Dist;
	return pForce;
}

bool    P2DForceKillPlane::Load(LuaPlus::LuaObject& _LObj)
{
    m_Dist = script::ScriptHelper::GetTableFloat(_LObj, "Height", 0.0f);
    return true;
}

bool	P2DForceKillPlane::RenderDebug(const math::Vec2& GroupCenter)
{
	dd::Manager::Instance().AddLine2D(math::Vec2(-1, m_Dist) , GroupCenter + math::Vec2(+1, m_Dist));
    return true;
}

bool	P2DForceKillPlane::MoveParticles(const math::Vec2& GroupCenter, Particle2D* _Particles, unsigned int _usCount, float dt)
{
    float   Height = m_Dist;
    for (unsigned int i=0; i<_usCount; i++)
    {
        Particle2D* pPart = &_Particles[i];
        if (pPart->Active)
        {
            if (pPart->Pos.y > Height)
                pPart->Kill = true;
        }
    }
    return true;
}
